<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        
    </body>
    <script>
        function * gen (arg){
            console.log(arg);// AAA
            let one = yield 111;
            console.log(one);// BBB
            let two = yield 222;
            console.log(two);// CCC
            let three = yield 333;
            console.log(three); // DDD
        }
        // 执行获取迭代器对象
        let iterator = gen("AAA");
        console.log(iterator);
        console.log(iterator.next());   //{value: 111, done: false}
        // next方法可以传入实参   参数为上一个yield语句参数的结果
        console.log(iterator.next("BBB"));//{value: 222, done: false}
        console.log(iterator.next("CCC"));//{value: 333, done: false}
        console.log(iterator.next("DDD"));//{value: undefined, done: true}
    </script>
</html>